package com.darren.center.design.patterns.dto;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * <h3>design-patterns</h3>
 * <p></p>
 *
 * @author : Darren
 * @date : 2021年06月14日 18:40:32
 **/
public class Context implements Serializable {

    private static final long serialVersionUID = 2881006635884953919L;
    private Map<String, Object> attrs;
    private String msgSeq;
    private String clientIP;// 用户IP

    public <T> void setAttr(String key, T value) {
        if (attrs == null) {
            attrs = new HashMap<String, Object>();
        }
        this.attrs.put(key, value);
    }

    @SuppressWarnings("unchecked")
    public <T> T getAttr(String key) {
        if (attrs != null) {
            return (T) this.attrs.get(key);
        }
        return null;
    }

    public Map<String, Object> getAttrs() {
        return attrs;
    }

    public void setAttrs(Map<String, Object> attrs) {
        this.attrs = attrs;
    }

    public String getMsgSeq() {
        return msgSeq;
    }

    public void setMsgSeq(String msgSeq) {
        this.msgSeq = msgSeq;
    }

    public String getClientIP() {
        return clientIP;
    }

    public void setClientIP(String clientIP) {
        this.clientIP = clientIP;
    }

    public Context() {
    }

    public Context(String msgSeq) {
        this.msgSeq = msgSeq;
    }

    @Override
    public String toString() {
        return "["+msgSeq+"]";
    }

}

